package com.yxuan.springboot.controller;

import com.yxuan.springboot.model.NoticRecord;
import com.yxuan.springboot.service.NoticRecordService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zchao
 * NoticRecord控制器
 * @date 2023-06-01 14:59:33
 */
@Controller
@Slf4j
@Api(tags = "")
@RequestMapping(value = "/noticrecord", method = {RequestMethod.POST, RequestMethod.GET})
public class NoticRecordController extends BaseController<NoticRecord> {

    @Autowired
    private NoticRecordService noticRecordService;

    //     根据前端触发的条件，发送消息
    @RequestMapping("/sendrecord")
    @ResponseBody
    public HashMap<String, Object> record(@RequestBody Map map) {
        try {
            return noticRecordService.record(map);
        } catch (Exception e) {
            HashMap<String, Object> result = new HashMap<>();
            log.error(e.getMessage());
            result.put("result", ERROR);
            return result;

        }
    }

    //    查看所有消息（逻辑删除的也看）
    @RequestMapping("/allrecord")
    @ResponseBody
    public HashMap<String, Object> allRecord(@RequestBody Map map) {
        try {
            return noticRecordService.allRecord(map);
        } catch (Exception e) {
            HashMap<String, Object> result = new HashMap<>();
            log.error(e.getMessage());
            result.put("result", ERROR);
            return result;

        }
    }

    //    根据用户id 查看消息（逻辑删除的不看）
    @RequestMapping("/recordbyid")
    @ResponseBody
    public HashMap<String, Object> recordById(@RequestBody Map map) {
        try {
            return noticRecordService.recordById(map);
        } catch (Exception e) {
            HashMap<String, Object> result = new HashMap<>();
            log.error(e.getMessage());
            result.put("result", ERROR);
            return result;

        }
    }

    //    阅读消息
    @RequestMapping("/readrecord")
    @ResponseBody
    public HashMap<String, Object> readRecord(@RequestBody Map map) {
        try {
            return noticRecordService.readRecord(map);
        } catch (Exception e) {
            HashMap<String, Object> result = new HashMap<>();
            log.error(e.getMessage());
            result.put("result", ERROR);
            return result;
        }
    }


    //    逻辑删除消息
    @RequestMapping("/logicdelrecord")
    @ResponseBody
    public HashMap<String, Object> logicDelRecord(@RequestBody Map map) {
        try {
            return noticRecordService.logicDelRecord(map);
        } catch (Exception e) {
            HashMap<String, Object> result = new HashMap<>();
            log.error(e.getMessage());
            result.put("result", ERROR);
            return result;
        }
    }

    //    未读消息的数量
    @RequestMapping("/unreadNum")
    @ResponseBody
    public HashMap<String, Object> unreadNum(@RequestBody Map map) {
        try {
            return noticRecordService.unreadNum(map);
        } catch (Exception e) {
            HashMap<String, Object> result = new HashMap<>();
            log.error(e.getMessage());
            result.put("result", ERROR);
            return result;
        }
    }


}
